<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改礼物')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-gift-edit" th:object="${ppGift}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">礼物名称：</label>
            <div class="col-sm-8">
                <input name="giftName" th:field="*{giftName}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">需要钻石数量：</label>
            <div class="col-sm-8">
                <input name="diamond" th:field="*{diamond}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">礼物金额：</label>
            <div class="col-sm-8">
                <input name="money" th:field="*{money}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="radio-box">
                    <select name="status">
                        <option th:value="1">启用</option>
                        <option th:value="0">取消</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">礼物图片：</label>
            <div class="col-sm-8">
                <!--<input type="hidden" name="giftUrl"/>
                <input id="giftUrl" name="giftUrl" type="file" onchange="gift()">
                <div id="editor" class="summernote"></div>-->
                <input id="giftUrl" name="files"  class="form-control" type="file" onchange="gift()">
                <input id="url" name="giftUrl" class="form-control aa" type="text" style="display: none">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-css"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: summernote-js" />
<script type="text/javascript">
    var prefix = ctx + "app/gift";

    $("#form-gift-edit").validate({
        focusCleanup: true
    });

    var img = [];
    //单独上传图片
    $(document).ready(function () {
        // console.log($('#form-village-add').serialize())
        $("#giftUrl").fileinput({
            showUpload: false,
            //设置语言
            language: 'zh',
            //异步上传
            uploadAsync: true,
            dropZoneEnabled: true,
            uploadUrl: ctx + "qiniu/uploadFiles",
            maxFileCount: 1,
            resizeImage: false,
            showCaption: false,
            showPreview: true,
            initialPreviewAsData:true,
            //预览项设置
            layoutTemplates:{
                //去除详细预览
                actionZoom:'',
            },
            initialPreview: [
                '[[${ppGift.giftUrl}]]'
            ],
            allowedFileTypes: ['image'],
            browseClass: "btn btn-primary btn-lg",
            //自动替换当前文件
            autoReplace:true,
        }).on("filebatchselected", function (event, files) {
            $(this).fileinput("upload");
        }).on("fileuploaded", function (event, data) {
            if (data.response) {
                img[img.length] = data.response.data[0].url;
                $(".aa").val(data.response.data[0].url);
            }
        });
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-gift-edit').serialize());
        }
    }
</script>
</body>
</html>